home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5634 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What to do when feof() is NOT feof()
  5. Date: 20 Feb 96 01:26:03 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824779563@rscernix>
  8. References: <824554814snz@metsys.demon.co.uk> <4g4vpp$52f@spectator.cris.com> <danpop.824614833@rscernix> <4g7t1r$71s@crl13.crl.com> <4gath3$abv@epx.cis.umn.edu>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4gath3$abv@epx.cis.umn.edu> thornley@cs.umn.edu (David H. Thornley) writes:
  13.  
  14. >tried to read past the end of file.  (Now, if feof() would tell me
  15. >that I'm *going* to read past EOF, I'd find it a bit more useful.)
  16.  
  17. Unfortunately, predicting the future is not an easy task :-)
  18. Let's consider a few examples:
  19.  
  20. - The stream is connected to a serial device in text mode.  No way to tell
  21.   whether the next character will be the end of file marker (if such a
  22.   beast is used) or if the tty driver will report EOF in five minutes,
  23.   because the user (who has just fallen asleep) will press the EOF
  24.   key combination.  A feof() which can block indefinitely is not
  25.   particularly desirable.
  26.  
  27. - The stream is connected to a file which is continuously growing, because
  28.   another program is madly writing into it.
  29.  
  30. - The stream is connected to a pipe.  It's difficult to tell what's
  31.   happening at the other end of the pipe.
  32.  
  33. The purpose of feof() is not to detect the end of file condition, but to
  34. report it.  It is typically used when another stdio function has returned
  35. an "error" condition and the programmer wants to know whether it was
  36. simply an attempt to read more data than was available on the stream and
  37. the data supply of that stream is definitively exhausted or something
  38. else happened on that stream.
  39.  
  40. To end the discussion on this topic, here's what the standard says about
  41. feof:
  42.  
  43.     4.9.10.2 The feof function
  44.  
  45.     Synopsis
  46.  
  47.          #include <stdio.h>
  48.          int feof(FILE *stream);
  49.  
  50.     Description
  51.  
  52.     The feof function tests the end-of-file indicator for the stream
  53.     pointed to by stream.
  54.  
  55.     Returns
  56.  
  57.     The feof function returns nonzero if and only if the end-of-file
  58.     indicator is set for stream.
  59.  
  60. Dan
  61. --
  62. Dan Pop
  63. CERN, CN Division
  64. Email: danpop@mail.cern.ch 
  65. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  66.